package com.chenwang.measure.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;

import com.chenwang.measure.R;
import com.chenwang.measure.base.BaseActivity;
import com.chenwang.measure.utils.MyToast;
import com.chenwang.measure.utils.SharePreferenceUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
//设置 服务器ip跟  下载人 姓名
public class SettingActivity extends BaseActivity {


    @BindView(R.id.et_name)
    EditText mEtName;
    @BindView(R.id.et_ip)
    EditText mEtIp;

    @Override
    public int setLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    public void initData() {
        super.initData();
        ButterKnife.bind(this);
        init();//初始化名字和ip

    }

    private void init(){
        String name = SharePreferenceUtils.getString(this,"username" ,"" );
        String ip = SharePreferenceUtils.getString(this,"ip" ,"" );
        if (!TextUtils.isEmpty(name)){
            mEtName.setText(name );
        }
        if (!TextUtils.isEmpty(ip)){
            mEtIp.setText(ip);
        }
    }



    @OnClick(R.id.btn)
    public void onViewClicked() {
            save();
    }

    //保存
    private void save(){
        String name = mEtName.getText().toString();
        String ip = mEtIp.getText().toString();
        SharePreferenceUtils.putString(this,"username" ,name );
        SharePreferenceUtils.putString(this,"ip" ,ip );
        MyToast.show("保存成功");
        finish();
    }

}
